package org.opens.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping(value = "/api/cookie")
@Slf4j
public class CookieController {

    @RequestMapping(value = "/destroy")
    public String destroyCookie(HttpServletRequest request, HttpServletResponse response) {
        Cookie[] cookies = request.getCookies();
        log.info("cookie start");
        for (Cookie cookie : cookies) {
            log.info("{}", cookie);
        }
        log.info("cookie end");

        Cookie cookie = new Cookie("username", "helloweenvsfei");
        cookie.setMaxAge(0);
        response.addCookie(cookie);
        return "hello";
    }

}
